﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 晨曦超市管理系统.员工管理
{
    public partial class YuanAdd : Form
    {
        public YuanAdd()
        {
            InitializeComponent();
        }

        private void YuanAdd_Load(object sender, EventArgs e)
        {
            radioButton1.Checked = true;
            comboBox1.Items.Add("管理员");
            comboBox1.Items.Add("收银员");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string Sex = "男";
                string Name = this.textBox1.Text.Trim();
                string JiGuan = this.textBox2.Text.Trim();
                if (radioButton1.Checked)
                {
                    Sex = "男";
                }
                if (radioButton2.Checked)
                {
                    Sex = "女";
                }
                string IDcard = this.textBox3.Text.Trim();
                string HireDate = dateTimePicker1.Value.ToString();
                string ContactAddress = this.textBox4.Text.Trim();
                string ContactNusmber = this.textBox5.Text.Trim();
                string Salary = this.textBox7.Text.Trim();
                string NianLing = this.textBox6.Text.Trim();
                string UserNameID = this.textBox9.Text.Trim();
                string Password = this.textBox8.Text.Trim();

                string Position = comboBox1.Text;
                string TiChen = textBox11.Text.Trim();
                string Remark = textBox12.Text.Trim();

                string sqlstr = "insert  informationOfEmployees(Name,JiGuan,Sex,IDcard,HireDate,ContactAddress,ContactNusmber,Salary,NianLing,UserNameID,Paw,Position,TiChen,Remark) values('" + Name + "','" + JiGuan + "','" + Sex + "','" + IDcard + "','" + HireDate + "','" + ContactAddress + "','" + ContactNusmber + "'," + Salary + "," + NianLing + "," + UserNameID + ",'" + Password + "','" + Position + "'," + TiChen + ",'" + Remark + "')";
                bool duicuo = DBHelper.QEX(sqlstr);
                if (duicuo)
                {
                    MessageBox.Show("添加成功");
                    radioButton1.Checked = true;
                    this.textBox1.Text = "";
                    this.textBox2.Text = "";
                    this.textBox3.Text = "";
                    this.textBox4.Text = "";
                    this.textBox5.Text = "";
                    this.textBox6.Text = "";
                    this.textBox7.Text = "";
                    this.textBox8.Text = "";
                    this.textBox9.Text = "";
                    this.textBox11.Text = "";
                    this.textBox12.Text = "";
                    comboBox1.SelectedIndex = 0;
                }
                else
                {
                    MessageBox.Show("添加失败");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this,"添加不成功请联系管理员原因："+ex.Message);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
